package view;

/**
 * Created by Pavel Nikolaev
 */
public class Selection {
    private int myMarkOffset;
    private int myDotOffset;
    private int myMarkViewIndex;
    private int myDotViewIndex;

    public Selection() {
        myMarkOffset = -1;
        myDotOffset = -1;
        myMarkViewIndex = 0;
        myDotViewIndex = 0;
    }

    public Selection(int mark, int dot) {
        this.myMarkOffset = mark;
        this.myDotOffset = dot;
    }

    public int getMarkOffset() {
        return myMarkOffset;
    }

    public int getDotOffset() {
        return myDotOffset;
    }

    public int getStartOffset() {
        return (myMarkOffset < myDotOffset) ? myMarkOffset : myDotOffset;
    }

    public void setMarkOffset(int mark) {
        this.myMarkOffset = mark;
    }

    public int getEndOffset() {
        return (myMarkOffset > myDotOffset) ? myMarkOffset : myDotOffset;
    }

    public void setDotOffset(int dot) {
        this.myDotOffset = dot;
    }

    public int getStartViewIndex() {
        return (myMarkViewIndex < myDotViewIndex) ? myMarkViewIndex : myDotViewIndex;
    }

    public void setMarkViewIndex(int index) {
        this.myMarkViewIndex = index;
    }

    public int getEndViewIndex() {
        return (myMarkViewIndex > myDotViewIndex) ? myMarkViewIndex : myDotViewIndex;
    }

    public void setDotViewIndex(int index) {
        this.myDotViewIndex = index;
    }

    public boolean isEmpty() {
        return (myDotOffset == myMarkOffset);
    }

    public void clear() {
        myDotOffset = myMarkOffset = -1;
        myDotViewIndex = myMarkViewIndex = 0;
    }

    @Override
    public String toString() {
        return super.toString() +
                " [" + String.valueOf(myMarkOffset) +
                ", " + String.valueOf(myDotOffset) + "]";
    }
}
